package neusoft.edu.cn.ui_demo.recyclerview;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import neusoft.edu.cn.ui_demo.R;

public class RecyclerViewActivity extends AppCompatActivity {

    private List<DateItem> dateItemList;
    RecyclerView recyclerView;
    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);

        context=RecyclerViewActivity.this;

        RecyclerViewAdapter viewAdapter = new RecyclerViewAdapter();

        viewAdapter.setDate(getDate());

        recyclerView = findViewById(R.id.recyclerView);

        //布局管理器  可以设置显示数据的方式为垂直或者水平
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);


        RecyclerViewAdapter.OnItemClickListener onItemClickListener = new RecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                System.out.println("aaaa666:");
                Toast.makeText(RecyclerViewActivity.this,"555"+getDate().get(position).getText1(), Toast.LENGTH_SHORT).show();

            }
        };

        viewAdapter.setOnItemClickListener(onItemClickListener);

        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(viewAdapter);

        //添加 Android内部提供的 默认水平分割线
//        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));

        //添加自己设计的分割线
        DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this,DividerItemDecoration.VERTICAL);
        dividerItemDecoration.setDrawable(ContextCompat.getDrawable(this,R.drawable.divider));
        recyclerView.addItemDecoration(dividerItemDecoration);

    }

    private List<DateItem> getDate() {
        List<DateItem> dateItemList = new ArrayList<>();

        for(int i=0;i<50;i++)
        {
            DateItem dateItem = new DateItem();

            dateItem.setUrl("image"+i);
            dateItem.setText1("Text1："+i);
            dateItem.setText2("Text2："+i);

            dateItemList.add(dateItem);
        }

        return dateItemList;
    }
}
